package com.ruoyi.web.controller.system;

import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;

import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.system.domain.TCkPickingwavegoodsBack;
import com.ruoyi.system.domain.TMiStockBack;
import com.ruoyi.system.service.TMiStockBackService;
import com.ruoyi.system.service.impl.TMiStockServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.time.LocalDate;
import java.time.temporal.ChronoUnit;
import java.util.List;

import static com.ruoyi.common.utils.PageUtils.startPage;
@RestController
@RequestMapping("/system/ckBack")
public class TMiStockBackController extends BaseController {

    @Autowired
    private TMiStockBackService tMiStockBackService;

    /**
     * 查询出库历史查询列表
     */
//    @PreAuthorize("@ss.hasPermi('system:BACK:list')")
//    @GetMapping("/first")
//    public TableDataInfo first(TCkPickingwavegoodsBack tCkPickingwavegoodsBack)
//    {
//        LocalDate today=LocalDate.now();
//        String endsTime = String.valueOf(today.plusDays(1));
//        String  sevenDaysAgo = String.valueOf(today.minus(7, ChronoUnit.DAYS));
//        tCkPickingwavegoodsBack.setStartTime(sevenDaysAgo);
//        tCkPickingwavegoodsBack.setEndsTime(endsTime);
//        startPage();
////        List<TCkPickingwavegoodsBack> list = tCkPickingwavegoodsBackService.selectFirstTCkPickingwavegoodsBackList(tCkPickingwavegoodsBack);
//        return getDataTable(list);
//    }
//
    /**
     * 查询出库历史查询列表
     */
    @PreAuthorize("@ss.hasPermi('system:BACK:list')")
    @GetMapping("/list")
    public TableDataInfo list(TMiStockBack tMiStockBack)
    {
        String[] addTimes = tMiStockBack.getWAREDATES();
        if (addTimes != null && addTimes.length > 1) {
            tMiStockBack.setStartTime(addTimes[0]);
            tMiStockBack.setEndsTime(addTimes[1]);
        }
        startPage();
        List<TMiStockBack> list = tMiStockBackService.selectTMiStockBackList(tMiStockBack);
        return getDataTable(list);
    }

//    /**
//     * 导出出库历史查询列表
//     */
//    @PreAuthorize("@ss.hasPermi('system:BACK:export')")
//    @Log(title = "出库历史查询", businessType = BusinessType.EXPORT)
//    @PostMapping("/export")
//    public void export(HttpServletResponse response, TCkPickingwavegoodsBack tCkPickingwavegoodsBack)
//    {
//        List<TCkPickingwavegoodsBack> list = tCkPickingwavegoodsBackService.selectTCkPickingwavegoodsBackList(tCkPickingwavegoodsBack);
//        ExcelUtil<TCkPickingwavegoodsBack> util = new ExcelUtil<TCkPickingwavegoodsBack>(TCkPickingwavegoodsBack.class);
//        util.exportExcel(response, list, "出库历史查询数据");
//    }
//
//    /**
//     * 获取出库历史查询详细信息
//     */
//    @PreAuthorize("@ss.hasPermi('system:BACK:query')")
//    @GetMapping(value = "/{PICKINGID}")
//    public AjaxResult getInfo(@PathVariable("PICKINGID") String PICKINGID)
//    {
//        return success(tCkPickingwavegoodsBackService.selectTCkPickingwavegoodsBackByPICKINGID(PICKINGID));
//    }
//
//    /**
//     * 新增出库历史查询
//     */
//    @PreAuthorize("@ss.hasPermi('system:BACK:add')")
//    @Log(title = "出库历史查询", businessType = BusinessType.INSERT)
//    @PostMapping
//    public AjaxResult add(@RequestBody TCkPickingwavegoodsBack tCkPickingwavegoodsBack)
//    {
//        return toAjax(tCkPickingwavegoodsBackService.insertTCkPickingwavegoodsBack(tCkPickingwavegoodsBack));
//    }
//
//    /**
//     * 修改出库历史查询
//     */
//    @PreAuthorize("@ss.hasPermi('system:BACK:edit')")
//    @Log(title = "出库历史查询", businessType = BusinessType.UPDATE)
//    @PutMapping
//    public AjaxResult edit(@RequestBody TCkPickingwavegoodsBack tCkPickingwavegoodsBack)
//    {
//        return toAjax(tCkPickingwavegoodsBackService.updateTCkPickingwavegoodsBack(tCkPickingwavegoodsBack));
//    }
//
//    /**
//     * 删除出库历史查询
//     */
//    @PreAuthorize("@ss.hasPermi('system:BACK:remove')")
//    @Log(title = "出库历史查询", businessType = BusinessType.DELETE)
//    @DeleteMapping("/{PICKINGIDs}")
//    public AjaxResult remove(@PathVariable String[] PICKINGIDs)
//    {
//        return toAjax(tCkPickingwavegoodsBackService.deleteTCkPickingwavegoodsBackByPICKINGIDs(PICKINGIDs));
//    }
}
